package com.yxplearn.mybatisplus.dao.core;

import com.yxplearn.mybatisplus.dao.core.handler.DefaultHandler;

import java.lang.reflect.Field;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Property {

    private Field field;
    private String columnName;
    private Class handler;

    public void getValue(ResultSet rs, Object newInstance) {
        try {
            DefaultHandler handlerObj = (DefaultHandler) handler.newInstance();
            field.set(newInstance, handlerObj.get(rs, columnName));
        } catch (IllegalAccessException | SQLException | InstantiationException e) {
            e.printStackTrace();
        }
    }

    public void setValue(PreparedStatement ps, Object value) {
    }

    public Field getField() {
        return field;
    }

    public void setField(Field field) {
        this.field = field;
    }

    public void setHandler(Class handler) {
        this.handler = handler;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }
}
